import {promptBox, toast} from 'nc-lightapp-front';
import {addCustomItemsValue, addCustomTemplateItems} from "../util/custom";


export default class MainAction {

    constructor(comp) {
        this.comp = comp;
    }

    editListAction = (record) => {
        const {dispatch, myLeave, form} = this.comp.props;
        let formCode = myLeave.activeTab + '_card'
        const {setFormStatus, setAllFormValue, EmptyAllFormValue, getFormItemsValue} = form
        EmptyAllFormValue(formCode)
        dispatch({
            type: 'myLeave/update',
            payload: {
                showMode: 'card',
                isEdit: true,
                approvestatus: record.values['approvestatus'] && record.values['approvestatus'].value
            }
        })
        setFormStatus(formCode, 'edit')
        setAllFormValue({
            [formCode]: {
                rows: [record]
            }
        })
    }

    updateStateCustom = (state) => {
        this.comp.props.dispatch({
            type: 'myLeave/update',
            state
        });
    }

    getClientHeight = () => {
        let {width} = document.querySelector('#app').getBoundingClientRect()
        let height = document.documentElement.clientHeight - 200;
        width = width - 256;
        this.comp.props.dispatch({
            type: 'myLeave/update',
            payload: {
                clientHeight: height,
                clientWidth: width
            }
        })
    }

    getTempalte = () => {
        const {dispatch} = this.comp.props;
        dispatch({
            type: 'myLeave/languageCreateUIDOM',
            payload: {
                ...this.comp.props,
                callback: this.initailMeta
            }
        })
    }

    getLangCode = (sName) => {
        var sRE = "(?:; )?" + sName + "=([^;]*);?";
        var oRE = new RegExp(sRE);
        if (oRE.test(document.cookie)) {
            return RegExp["$1"];
        }
        return null;
    }

    addOperateCol = (template, buttons) => {
        const {myLeave, button} = this.comp.props;
        let langCode = this.getLangCode('langCode');
        let oprWidth = '160px', oproffWidth = '160px'
        let key = 'leave_list'
        if (langCode === 'english') {
            oprWidth = '250px'
            oproffWidth = '250px'
        }
        let render = (text, record, index) => {

            let edit = record.values.billtype.value === '6QQJ'
                && record.values.approvestatus
                && record.values.approvestatus.value === '-1'
            let recall = record.values.approvestatus
                && (record.values.approvestatus.value - 0) === 3
            let revoke = record.values.billtype.value === '6QQJ'
                && record.values.approvestatus
                && record.values.approvestatus.value === '1'
                && (record.values.billsource.value
                    && record.values.billsource.value === '0')
                && (record.values.leaveoffapprovestatus
                    && !record.values.leaveoffapprovestatus.value)

            let listBtns = []
            buttons.forEach(btn => {
                if (btn.area === 'list') {
                    if ((btn.key === 'list_submit' || btn.key === 'list_edit'
                        || btn.key === 'list_del') && !edit) {
                        return
                    }
                    if (btn.key === 'list_withdraw' && !recall) {
                        return
                    }
                    if (btn.key === 'list_revoke' && !revoke) {
                        return
                    }
                    listBtns.push(btn.key)
                }
            })

            return (
                <div className="currency-opr-col">
                    {button.createOprationButton(listBtns,
                        {
                            area: 'list',
                            buttonLimit: 2,
                            onButtonClick: (props, id, e) => {
                                this.listClickHandle(id, record)
                            }
                        }
                    )}
                </div>
            );
        }
        let renderoff = (text, record, index) => {
            let edit = record.values.leaveoffapprovestatus
                && record.values.leaveoffapprovestatus.value === '-1'
            let recall = record.values.leaveoffapprovestatus.value === '3'
            let offBtns = []
            if (record.values.leaveoffapprovestatus && record.values.leaveoffapprovestatus.value) {
                buttons.forEach(btn => {
                    if (btn.area === 'list_off') {
                        if ((btn.key === 'off_submit' || btn.key === 'off_edit'
                            || btn.key === 'off_del') && !edit) {
                            return
                        }
                        if (btn.key === 'off_withdraw' && !recall) {
                            return
                        }
                        offBtns.push(btn.key)
                    }
                })
            }

            return (
                <div className="currency-opr-col">
                    {button.createOprationButton(offBtns,
                        {
                            area: 'list_off',
                            buttonLimit: 2,
                            onButtonClick: (props, id, e) => {
                                this.listOffClickHandle(id, record)
                            }
                        }
                    )}
                </div>
            );
        }

        template[key].items.push({
            attrcode: 'operation',
            renderStatus: 'browse',
            itemtype: 'customer',
            label: myLeave.json['6040-000019'], /* 国际化处理： 操作*/
            width: oprWidth,
            visible: true,
            fixed: 'right',
            render: render
        })
        template[key].items.push({
            attrcode: 'oproff',
            renderStatus: 'browse',
            itemtype: 'customer',
            label: myLeave.json['6040-000029'],
            width: oproffWidth,
            visible: true,
            fixed: 'right',
            render: renderoff
        })
    }

    listClickHandle = (key, record) => {
        if (key === 'list_flow') {
            this.showFlowHistory(record, 1)
        } else if (key === 'list_withdraw') {
            this.recallBill(record)
        } else if (key === 'list_revoke') {
            this.linkBill(record)
        } else if (key === 'list_submit') {
            this.submitBill(record, 'leave')
        } else if (key === 'list_file') {
            this.showUploader(record);
        } else if (key === 'list_edit') {
            this.editBill(record);
        } else if (key === 'list_del') {
            this.deleteBill(record, 'leave');
        }
    }

    listOffClickHandle = (key, record) => {
        if (key === 'off_flow') {
            this.showFlowHistory(record, 2)
        } else if (key === 'off_withdraw') {
            this.recallBill(record)
        } else if (key === 'off_check') {
            this.onLookClick(record)
        } else if (key === 'off_submit') {
            this.submitBill(record, 'leaveoff')
        } else if (key === 'off_edit') {
            this.onLookClick(record, 'edit');
        } else if (key === 'off_del') {
            this.deleteBill(record, 'leaveoff');
        }
    }

    initailMeta = (metas, lang, intl) => {
        let {button, template} = metas;
        const props = this.comp.props;
        const {renderItem, meta, dispatch} = props;
        dispatch({
            type: 'myLeave/update',
            payload: {
                json: lang
            }
        })
        this.addOperateCol(template, button);
        this.handleMeta(template, renderItem)
        meta.setMeta(template ? template : {});
        props.button.setButtons(button);
        dispatch({
            type: 'myLeave/update',
            payload: {
                templateInited: true
            }
        })
    }

    handleMeta = (template, renderItem) => {
        const {myLeave} = this.comp.props;
        let target = ['leave_card', 'leaveoff_card'];
        target.forEach(key => {
            template[key].items.forEach(item => {
                if (key === 'leave_card') {
                    if (item.attrcode === 'leaveday' || item.attrcode === 'vacationquota') {
                        item.itemtype = 'input'
                    }
                    if (item.attrcode === 'transtypeid') {
                        if (!item.queryCondition) {
                            item.queryCondition = {
                                GridRefActionExt: "nccloud.web.hrkq.leave.sqlbuilder.LeaveTransTypeRefSqlBuilder"
                            }
                        } else {
                            item.queryCondition = Object.assign(item.queryCondition, {
                                GridRefActionExt: "nccloud.web.hrkq.leave.sqlbuilder.LeaveTransTypeRefSqlBuilder"
                            })
                        }
                    } else if (item.attrcode === "pk_attend_staff") {
                        if (!item.queryCondition) {
                            item.queryCondition = {}
                        }
                        item.queryCondition = Object.assign(item.queryCondition, {
                            isSingle: "1"
                        })
                    }
                }
                if (key === 'leaveoff_card') {
                    if (item.attrcode === 'leaveoffday' || item.attrcode === 'vacationquota' || item.attrcode === 'leaveday') {
                        item.itemtype = 'input'
                    }
                    if (item.attrcode === 'transtypeid') {
                        if (!item.queryCondition) {
                            item.queryCondition = {
                                GridRefActionExt: "nccloud.web.hrkq.leaveoff.sqlbuilder.LeaveOffTransTypeRefSqlBuilder"
                            }
                        } else {
                            item.queryCondition = Object.assign(item.queryCondition, {
                                GridRefActionExt: "nccloud.web.hrkq.leaveoff.sqlbuilder.LeaveOffTransTypeRefSqlBuilder"
                            })
                        }
                    }
                }
            })
        })
    }
    /**
     * @desc: 根据休假类型的单位和最小请假时间 格式化请假时间
     * @param {type}
     * @return: 最终要显示的日期
     */
    formatDisplayDate = (record, attrcode) => {
        if (!record || !record.values || !record.values[attrcode].value) {
            return '';
        }
        let isHour = record.values['minunit'].value === '1';
        let isHalfDate = !!record.values['start_day_type'].value;
        let values = record.values;
        if (values.breastfeedingleaveday && values.breastfeedingleaveday.value && values.breastfeedingleaveway && values.breastfeedingleaveway.value) {
            // 如果是哺乳假 则 返回 日期 不返回小时 分钟
            return record.values[attrcode].value.slice(0, -8);
        }

        if (isHour) {
            return record.values[attrcode].value.slice(0, -3);
        } else {
            attrcode = attrcode === 'begintime' ? 'showbegindate' : 'showenddate';
            if (isHalfDate) {
                return record.values[attrcode].value.replace(/\s([\d\:]+)/, (a, b) => {
                    return attrcode === 'showbegindate' ? record.values['start_day_type'].display : record.values['end_day_type'].display;
                })
            } else {
                return record.values[attrcode].value.slice(0, -8);
            }
        }
    }
    /**
     * @desc:
     * @return:
     * @param record
     * @param type
     */
    showFlowHistory = (record, type) => {
        const {dispatch} = this.comp.props;
        let billId
        let billtype
        if (type === 1) {
            billtype = (record.values['transtype'] && record.values['transtype'].value) || '6QQJ'
            billId = record.values['pk_leave'].value;
        } else if (type === 2) {
            billtype = (record.values['leaveofftranstype'] && record.values['leaveofftranstype'].value) || '6QXJ'
            billId = record.values['pk_leaveoff'].value;
        }

        dispatch({
            type: 'myLeave/update',
            payload: {
                showApproveDetail: true,
                billId,
                billtype
            }
        })
    }
    /**
     * @desc: 跳转销差销假操作
     * @return:
     *
     * @param record
     */
    linkBill = (record) => {
        const formCode = record.values.billtype.value === '6QQJ' ? 'leaveoff_card' : 'tripoff_card'
        const activeTab = record.values.billtype.value === '6QQJ' ? 'leaveoff' : 'tripoff'
        const {dispatch, form} = this.comp.props
        const {
            EmptyAllFormValue
        } = form
        EmptyAllFormValue(formCode)
        dispatch({
            type: 'myLeave/AddAction',
            payload: {
                key: activeTab,
                operat: 0,
                pk_other: activeTab === 'leaveoff' ? record.values.pk_leave.value : record.values.pk_trip.value
            }
        }).then(res => {
            this.setRecokeValue(this.comp.props, res.data[formCode], record, 'add')
        })

    }

    submitBill = (record, key) => {
        const {dispatch, myLeave} = this.comp.props;
        dispatch({
            type: 'myLeave/submitBillAction',
            payload: {
                key,
                pk: record.values['pk_' + key].value
            }
        }).then(res => {
            if (res.success) {
                if (res.data && res.data.content) {
                    dispatch({
                        type: 'myLeave/update',
                        payload: {
                            assignedData: res.data.content,
                            assignedDisplay: true
                        }
                    })
                } else {
                    toast({
                        color: 'success',
                        content: myLeave.json['6040-00004']  // 提交成功！
                    });
                    this.queryListAction()
                }
            }
        })
    }

    editBill = (record) => {
        const {dispatch, myLeave, form} = this.comp.props;
        let minTime = '';
        let formCode = myLeave.activeTab + '_card';
        const {
            setFormStatus,
            setAllFormValue,
            setItemsVisible,
            EmptyAllFormValue,
            setFormItemsValue,
            setFormItemsDisabled
        } = form;
        EmptyAllFormValue(formCode);
        setFormStatus(formCode, 'edit');
        setAllFormValue({
            [formCode]: {
                rows: [record]
            }
        })
        if (formCode === 'leave_card') {
            let dayKey = 'leaveday';
            let minunit = record.values.minunit.value;
            setFormItemsValue(formCode, {
                [dayKey]: {
                    display: record.values[dayKey].value + record.values['minunit'].display,
                    value: record.values[dayKey].value
                }
            });
            let leaveway = record.values.breastfeedingleaveway && record.values.breastfeedingleaveway.value
            // 判断是否为半天假
            let start_day_type = record.values.start_day_type && record.values.start_day_type.value;
            if (leaveway) {
                setItemsVisible(formCode, {
                    'breastfeedingleaveway': true,
                    'breastfeedingleaveday': true,
                    'leaveday': false,
                    endtime: false,
                    begin: false,
                    showbegindate: true,
                    showenddate: true
                })
            }
            let cardDefaultDisabled = {
                showbegindate: false, // 开始日期
                showenddate: false, // 结束日期
                begintime: false, // 结束日期
                endtime: false, // 结束日期
                start_day_type: false, // 结束日期
                end_day_type: false // 结束日期
            }
            setFormItemsDisabled(formCode, cardDefaultDisabled);
            dispatch({
                type: 'myLeave/update',
                payload: {
                    feedStatus: !!leaveway
                }
            })
            minTime = start_day_type ? '1' : '2'
            this.initCardMeta(start_day_type, minunit, formCode, !!leaveway, record);
            this.initLeaveData();
        }
        dispatch({
            type: 'myLeave/update',
            payload: {
                showMode: 'card',
                isEdit: true,
                minTime,
                billId: record.values['pk_' + myLeave.activeTab].value,
                headerTitle: myLeave.subTitle,
                approvestatus: record.values['approvestatus'] && record.values['approvestatus'].value
            }
        })
    }

    initCardMeta = (halfDate, minunit = '1', formCode, feedStatus = false, record) => {
        const {form, myLeave} = this.comp.props;
        const {setItemsVisible, setFormItemsRequired, getFormItemsVisible} = form;
        let obj = {};
        let flag = minunit === '1';
        let flag1 = minunit === '2';
        let flag2 = minunit === '2' && halfDate;
        let cardDefaultVisiable = {
            'breastfeedingleaveway': false,
            'breastfeedingleaveday': false,
            'showbegindate': false, // 开始日期
            'showenddate': false, // 结束日期
            'begintime': true, // 开始时间
            'endtime': true, // 结束时间
            'start_day_type': false, // 结束日期
            'end_day_type': false, // 结束日期
            'leaveday': true, // 结束日期
            'vacationquota': false // 休假额度   默认不显示
        }
        // const vacationquota = record && record.values && record.values.vacationquota && record.values.vacationquota.value;
        // cardDefaultVisiable.vacationquota = !!(vacationquota && vacationquota > 0)
        if (formCode === 'leave_card') {
            if (feedStatus) {
                cardDefaultVisiable.breastfeedingleaveway = true
                cardDefaultVisiable.breastfeedingleaveday = true
                cardDefaultVisiable.showbegindate = true // 开始日期
                cardDefaultVisiable.showenddate = true // 结束日期
                cardDefaultVisiable.begintime = false // 开始时间
                cardDefaultVisiable.endtime = false // 结束时间
                cardDefaultVisiable.leaveday = false // 请假时长
                obj = {
                    begintime: false,
                    endtime: false,
                    showbegindate: true,
                    showenddate: true,
                    start_day_type: false,
                    end_day_type: false,
                    vacationquota: false
                }
            } else {
                cardDefaultVisiable.begintime = flag
                cardDefaultVisiable.endtime = flag
                cardDefaultVisiable.showbegindate = flag1
                cardDefaultVisiable.showenddate = flag1
                cardDefaultVisiable.start_day_type = flag2
                cardDefaultVisiable.end_day_type = flag2
                obj = {
                    begintime: flag,
                    endtime: flag,
                    showbegindate: flag1,
                    showenddate: flag1,
                    start_day_type: flag2,
                    end_day_type: flag2,
                    vacationquota: false
                }
            }

        }
        setItemsVisible(formCode, cardDefaultVisiable);
        setFormItemsRequired(formCode, obj);
    }

    initLeaveData = () => {
        const formCode = 'leave_card'
        const {dispatch, myLeave, form, meta: metas} = this.comp.props;
        const {getAllFormValue, setFormItemsValue, getFormItemsValue, setItemsVisible} = form;
        dispatch({
            type: 'myLeave/afterEditCard',
            payload: {
                formData: {
                    model: getAllFormValue(formCode)
                },
                attrCode: 'pk_leave_type'
            }
        }).then(res => {
            if (res.success) {
                if (res.data && res.data.valueMap) {
                    if (res.data.extend && res.data.extend['isattachment']) {
                        // todo   附件上传是否必须
                        let isattachment = res.data.extend['isattachment']
                        let excessLength = res.data.extend['attachmentExcessDay'] || res.data.extend['attachmentExcessHour'] || '0'
                        dispatch({
                            type: 'myLeave/update',
                            payload: {
                                isattachment,
                                excessLength
                            }
                        })
                    }
                    const valueMapTemp = {
                        ...res.data.valueMap,
                        // ...addCustomItemsValue(res.data.valueMap, 'vacationquota', 0),
                    };
                    // addCustomTemplateItems({
                    //     metas,
                    //     form,
                    //     formCode
                    // }, res.data.valueMap, 'vacationquota', myLeave.json['6040-000037']);
                    setFormItemsValue(formCode, valueMapTemp)
                    // islimit '0' 不显示休假额度  '1' 显示休假额度
                    const vacationquotaDisplay = getFormItemsValue(formCode, 'islimit').value === '1';
                    const customTemplateItemKeys = getFormItemsValue(formCode, 'vacationquota').value === null
                        ? ['default']
                        : Object.keys(getFormItemsValue(formCode, 'vacationquota').value);
                    dispatch({
                        type: 'myLeave/update',
                        payload: {
                            customTemplateItemKeys,
                        }
                    })
                    // customTemplateItemKeys.forEach(key => {
                    //     setItemsVisible(formCode, {[`custom_vacationquota_${key}`]: vacationquotaDisplay});
                    // });
                    setItemsVisible(formCode, {leavequotainfo: vacationquotaDisplay});
                    if (!vacationquotaDisplay) {
                        setFormItemsValue(formCode, {
                            leavequotainfo: {
                                display: null,
                                value: null
                            }
                        })
                    }
                }
            }
        })
    }

    deleteBill = (record, key) => {
        const {dispatch, myLeave} = this.comp.props
        promptBox({
            color: "warning",
            title: myLeave.json['6040-00005'], /* 国际化处理： 提示*/
            content: myLeave.json['6040-000060'],
            beSureBtnClick: () => {
                dispatch({
                    type: 'myLeave/deleteAction',
                    payload: {
                        activeTab: key,
                        pk: record.values['pk_' + key].value
                    }
                }).then(res => {
                    if (res.success) {
                        toast({
                            color: 'success',
                            content: myLeave.json['6040-000012']
                        })
                        this.queryListAction();
                    }
                })
            }
        })
    }

    showUploader = (record) => {
        const {dispatch} = this.comp.props;
        dispatch({
            type: 'myLeave/update',
            payload: {
                showUploader: true,
                billId: record.values['pk_leave'].value,
                approvestatus: record.values['approvestatus'].value,
            }
        })
    }

    setRecokeValue(props, template, record, status) {
        const {dispatch, form, myLeave} = props
        const formCode = 'leaveoff_card'
        const activeTab = 'leaveoff'
        const titleName = myLeave.json['6040-000030']
        let minTime = '1'
        let feedStatus = false
        let cardDefaultVisiable = {}
        let cardDefaultDisabled = {}
        const {
            setFormStatus,
            setAllFormValue,
            getFormItemsValue,
            setItemsVisible,
        } = form
        if (formCode === 'leaveoff_card') {
            const breastfeedingleaveway = record.values.breastfeedingleaveway.value
            const halfDay = record.values.start_day_type.value
            const minunit = record.values.minunit.value
            let dr_flag = template.rows[0].values.dr_flag.value
            //小时显示组件
            cardDefaultVisiable = {
                leaveshowbegindate: false, // 请假开始日期
                leaveshowenddate: false, // 请假结束日期
                leavebegintime: true, // 请假开始时间
                leaveendtime: true, // 请假结束时间
                leave_start_day_type: false, // 请假上午标记
                leave_end_day_type: false, // 请假上午标记
                leaveoff_start_day_type: false, // 结束日期
                leaveoff_end_day_type: false, // 结束日期
                vacationquota: false,// 休假额度   默认不显示
                leaveoffshowbegindate: false, // 开始日期
                leaveoffshowenddate: false, // 结束日期
                leaveoffbegintime: true, // 开始时间
                leaveoffendtime: true, // 结束时间
                leaveoffday: true, // 实际休假时长
                breastfeedingleaveday: false, // 每天休假时长
                breastfeedingleaveway: false, // 休假方式
            }
            // 天显示组件
            if (minunit === '2') {
                minTime = '2'
                cardDefaultVisiable.leaveshowbegindate = true // 请假开始日期
                cardDefaultVisiable.leaveshowenddate = true // 请假结束日期
                cardDefaultVisiable.leavebegintime = false // 请假开始时间
                cardDefaultVisiable.leaveendtime = false // 请假结束时间
                cardDefaultVisiable.vacationquota = false // 休假额度   默认不显示
                cardDefaultVisiable.leaveoffshowbegindate = true // 开始日期
                cardDefaultVisiable.leaveoffshowenddate = true // 结束日期
                cardDefaultVisiable.leaveoffbegintime = false // 开始时间
                cardDefaultVisiable.leaveoffendtime = false // 结束时间
            }
            // 哺乳假显示
            if (breastfeedingleaveway) {
                feedStatus = true
                minTime = '2'
                cardDefaultVisiable.leaveshowbegindate = false // 请假开始日期
                cardDefaultVisiable.leaveshowenddate = false // 请假结束日期
                cardDefaultVisiable.leavebegintime = true // 请假开始时间
                cardDefaultVisiable.leaveendtime = true // 请假结束时间
                cardDefaultVisiable.vacationquota = false // 休假额度   默认不显示
                cardDefaultVisiable.leaveoffshowbegindate = false // 开始日期
                cardDefaultVisiable.leaveoffshowenddate = false // 结束日期
                cardDefaultVisiable.leaveoffbegintime = true // 开始时间
                cardDefaultVisiable.leaveoffendtime = true // 结束时间
                cardDefaultVisiable.breastfeedingleaveday = true // 每天休假时长
                cardDefaultVisiable.breastfeedingleaveway = true // 休假方式
                cardDefaultVisiable.leaveoffday = false // 实际休假时长
            }
            // 半天假显示
            if (halfDay && !breastfeedingleaveway) {
                minTime = '1'
                cardDefaultVisiable.leave_start_day_type = true // 请假上午标记
                cardDefaultVisiable.leave_end_day_type = true // 请假上午标记
                cardDefaultVisiable.leaveoff_start_day_type = true // 销假上午
                cardDefaultVisiable.leaveoff_end_day_type = true // 销假下午
            }
            // 设置半天假
            if (dr_flag === '1') {
                cardDefaultVisiable.leaveoffshowbegindate = false // 开始日期
                cardDefaultVisiable.leaveoffshowenddate = false // 结束日期
                cardDefaultVisiable.leaveoffbegintime = false // 开始时间
                cardDefaultVisiable.leaveoffendtime = false // 结束时间
                cardDefaultVisiable.leaveoffday = false // 结束时间
                cardDefaultVisiable.leaveoff_start_day_type = false // 销假上午
                cardDefaultVisiable.leaveoff_end_day_type = false // 销假下午
            }
            template.rows[0].values.leaveday.display = `${template.rows[0].values.leaveday.value}${template.rows[0].values.minunit.value === "1" ? myLeave.json['6040-000014'] : myLeave.json['6040-000015']}`
            template.rows[0].values.leaveoffday.display = template.rows[0].values.leaveoffday.value ? `${template.rows[0].values.leaveoffday.value}${template.rows[0].values.minunit.value === "1" ? myLeave.json['6040-000014'] : myLeave.json['6040-000015']}` : null
        }
        setItemsVisible(formCode, cardDefaultVisiable);
        dispatch({
            type: 'myLeave/update',
            payload: {
                feedStatus,
                showMode: 'card',
                isEdit: status === 'add',
                headerTitle: titleName
            }
        })
        setAllFormValue({[formCode]: template});
        let billId = getFormItemsValue(formCode, 'pk_' + activeTab).value;
        let approvestatus = getFormItemsValue(formCode, 'approvestatus').value;
        dispatch({
            type: 'myLeave/update',
            payload: {
                billId,
                minTime,
                activeTab: activeTab,
                approvestatus
            }
        })
        cardDefaultVisiable = null
        cardDefaultDisabled = null
        setFormStatus(formCode, status)
    }

    setDataType(props, minunit, minTime, formId) {
        let meta = props.meta.getMeta()
        let template = meta[formId]
        let templateItems = template.items || []
        let itemType = minunit === '2' ? 'datepicker' : 'datetimepicker'
        let attrcodes = ['leaveoffbegintime', 'leaveoffendtime']
        templateItems.forEach(item => {
            if (attrcodes.includes(item.attrcode)) {
                item.itemtype = itemType
            }
        })
        props.meta.setMeta(meta, () => {
            props.form.updateForm(formId)
        })
    }

    /**
     * @desc: record(行数据) ，index(当前index) props, e (事件对象)
     * @return:
     * @param record
     */
    onLookClick = (record, status = 'browse') => {
        const {dispatch, myLeave, form} = this.comp.props
        let formCode = myLeave.activeTab + 'off' + '_card';
        const activeTab = 'leaveoff'
        const {
            EmptyAllFormValue
        } = form
        EmptyAllFormValue(formCode)
        dispatch({
            type: 'myLeave/queryByIdAction',
            payload: {
                key: activeTab,
                pk: record.values['pk_' + myLeave.activeTab].value
            }
        }).then(res => {
            this.setRecokeValue(this.comp.props, res.data[myLeave.activeTab + 'off'][formCode], record, status)
        })
    }
    /**
     * @desc: 单据撤回操作
     * @param {type}
     * @return:
     */
    recallBill = (record) => {
        const {dispatch, myLeave, editTable} = this.comp.props;
        let pk = record.values['pk_' + myLeave.activeTab].value;
        let tableCode = myLeave.activeTab + '_list';
        let activeTab = myLeave.activeTab
        let status = record.values.approvestatus.value;
        let revokestatus = record.values.approvestatus.value === '1' && (record.values.tripoffapprovestatus && record.values.tripoffapprovestatus.value || record.values.leaveoffapprovestatus && record.values.leaveoffapprovestatus.value)
        if (status === '1' && revokestatus === '3') {
            pk = record.values['pk_' + myLeave.activeTab + 'off'].value;
            activeTab = myLeave.activeTab + 'off'
        }
        promptBox({
            color: "warning",
            title: myLeave.json['6040-00005'], /* 国际化处理： 提示*/
            content: myLeave.json['6040-000023'], /* 国际化处理： 你确定要撤回该单据吗？*/
            beSureBtnClick: () => {
                dispatch({
                    type: 'myLeave/recallAction',
                    payload: {
                        key: activeTab,
                        pk
                    }
                }).then(res => {
                    if (res.success) {
                        toast({
                            color: 'success',
                            content: myLeave.json['6040-000024']
                        });
                        this.queryListAction()
                    }
                })
            }
        })
    }
    closeApproveDetailDialog = () => {
        const {dispatch} = this.comp.props;
        dispatch({
            type: 'myLeave/update',
            payload: {
                showApproveDetail: false
            }
        })
    }

    handlePageIndexChange = (pageIndex) => {
        const {dispatch, myLeave} = this.comp.props
        let pageInfo = myLeave.activeTab + 'PageInfo'
        dispatch({
            type: 'myLeave/update',
            payload: {
                [pageInfo]: Object.assign({}, myLeave[pageInfo], {
                    pageIndex
                })
            }
        })
        this.queryListAction()
    }

    queryListAction = () => {
        const {dispatch, myLeave, editTable} = this.comp.props;
        let tableCode = myLeave.activeTab + '_list';
        let activeTab = myLeave.activeTab
        dispatch({
            type: 'myLeave/queryListAction',
            payload: {
                key: myLeave.activeTab,
                beginDate: myLeave.beginValue,
                endDate: myLeave.endValue
            }
        }).then(res => {
            if (res.success) {
                if (res.data) {
                    editTable.setTableData(tableCode, res.data[tableCode])
                    dispatch({
                        type: 'myLeave/update',
                        payload: {
                            [activeTab + 'PageInfo']: res.data[tableCode].pageInfo
                        }
                    })
                } else {
                    editTable.setTableData(tableCode, {rows: []})
                    dispatch({
                        type: 'myLeave/update',
                        payload: {
                            [activeTab + 'PageInfo']: Object.assign({}, myLeave[activeTab + 'PageInfo'], {total: null})
                        }
                    })
                }
            }
        })
    }

    didMount = () => {
        if (window.location.href.match(/(localhost|127\.0\.0\.1)/)) {
            window.location.hash = `#ifr?page=2019916105952100`;
        }
        this.getClientHeight()
        this.getTempalte()
    }
}